/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.company.regis.controller;

import com.company.regis.report.bean.MapScore;
import java.math.BigDecimal;
import java.util.HashMap;
import java.util.Map;
import javax.annotation.PostConstruct;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 *
 * @author totoland
 */
@ViewScoped
@ManagedBean
public class FormController extends BaseController {

    private static final long serialVersionUID = 7673568034372598872L;

    private static Logger logger = LoggerFactory.getLogger(FormController.class);

    private Integer scoring1 = 0;
    private Integer scoring2 = 0;

    private Integer totalScore = 0;
    private String benchMark;
 /***
  * ทุนเอาประกันภัย 
  */
    private BigDecimal costOfInsurance = new BigDecimal(1000000.00);
    
    @PostConstruct
    public void init() {

    }

    public Double calExtra(BigDecimal bd,BigDecimal bd1){
        if(bd.doubleValue()== 0 || bd1.doubleValue() == 0){
            return 0.00;
        }
        return bd.doubleValue()/bd1.doubleValue();
    }
    
    /**
     * *
     * aaa	14001 - 16000 bbb	12001 - 14000 ccc	10001 - 12000 ddd	8001 - 10000
     * eee	6001 - 8000 fff	4001 - 6000 ggg	2001 - 4000 hhh	1 - 2000
     */
    public void submitScore() {

        logger.trace("scoring1 : {} scoring2 : {}", scoring1, scoring2);

        totalScore = scoring1 + scoring2;

        logger.trace("totalScore : {}", totalScore);

        if (totalScore >= 14001 && totalScore <= 16000) {

            benchMark = "aaa";

        } else if (totalScore >= 12001 && totalScore <= 14000) {

            benchMark = "bbb";

        } else if (totalScore >= 10001 && totalScore <= 12000) {

            benchMark = "ccc";

        } else if (totalScore >= 8001 && totalScore <= 10000) {

            benchMark = "ddd";

        } else if (totalScore >= 6001 && totalScore <= 8000) {

            benchMark = "eee";

        } else if (totalScore >= 4001 && totalScore <= 6000) {

            benchMark = "fff";

        } else if (totalScore >= 2001 && totalScore <= 4000) {

            benchMark = "ggg";

        } else if (totalScore >= 1 && totalScore <= 2000) {

            benchMark = "hhh";

        } else{
            benchMark = "";
        }

        logger.trace("benchMark : {} ", benchMark);

    }

    public MapScore getMap(String key) {

        Map<String, MapScore> map = new HashMap<String, MapScore>();
        map.put("aaa", new MapScore("aaa", 0, new BigDecimal(0.000000), new BigDecimal(0.000000),new BigDecimal(0.008000)));
        map.put("bbb", new MapScore("bbb", 0, new BigDecimal(0.000000), new BigDecimal(0.000000),new BigDecimal(0.010000)));
        map.put("ccc", new MapScore("ccc", 0, new BigDecimal(0.010000), new BigDecimal(0.010000),new BigDecimal(0.015150)));
        map.put("ddd", new MapScore("ddd", 0, new BigDecimal(0.020000), new BigDecimal(0.020000),new BigDecimal(0.020400)));
        map.put("eee", new MapScore("eee", 0, new BigDecimal(0.030000), new BigDecimal(0.030000),new BigDecimal(0.030900)));
        map.put("fff", new MapScore("fff", 0, new BigDecimal(0.050000), new BigDecimal(0.050000),new BigDecimal(0.052500)));
        map.put("ggg", new MapScore("ggg", 0, new BigDecimal(0.100000), new BigDecimal(0.100000),new BigDecimal(0.110000)));
        map.put("hhh", new MapScore("hhh", 0, new BigDecimal(0.200000), new BigDecimal(0.200000),new BigDecimal(0.240000)));

        if(!map.containsKey(key)){
            return new MapScore(benchMark, 0, BigDecimal.ZERO, BigDecimal.ZERO, BigDecimal.ZERO);
        }
        
        return (MapScore)map.get(key);
        
    }

    /**
     * @return the scoring1
     */
    public Integer getScoring1() {
        return scoring1;
    }

    /**
     * @param scoring1 the scoring1 to set
     */
    public void setScoring1(Integer scoring1) {
        this.scoring1 = scoring1;
    }

    /**
     * @return the scoring2
     */
    public Integer getScoring2() {
        return scoring2;
    }

    /**
     * @param scoring2 the scoring2 to set
     */
    public void setScoring2(Integer scoring2) {
        this.scoring2 = scoring2;
    }

    /**
     * @return the totalScore
     */
    public Integer getTotalScore() {
        return totalScore;
    }

    /**
     * @param totalScore the totalScore to set
     */
    public void setTotalScore(Integer totalScore) {
        this.totalScore = totalScore;
    }

    /**
     * @return the benchMark
     */
    public String getBenchMark() {
        return benchMark;
    }

    /**
     * @param benchMark the benchMark to set
     */
    public void setBenchMark(String benchMark) {
        this.benchMark = benchMark;
    }

    /**
     * @return the costOfInsurance
     */
    public BigDecimal getCostOfInsurance() {
        return costOfInsurance;
    }

    /**
     * @param costOfInsurance the costOfInsurance to set
     */
    public void setCostOfInsurance(BigDecimal costOfInsurance) {
        this.costOfInsurance = costOfInsurance;
    }

}
